//:C13:NoMemory.cpp
// Constructor isn't callded f new fails
#include <iostream>
#include <new>    // bad_alloc definition
using namespace std;

class NoMemory
{
    public:
        NoMemory()
        {
            cout << "NoMemory::NoMemory()" << endl;
        }
        void *operator new(size_t sz) throw(bad_alloc)
        {
            cout << "NoMemory::operator new" << endl;
            throw bad_alloc();    // "Out of memory"
        }
};

int main(void)
{
    NoMemory *nm = 0;
    try{
        nm = new NoMemory;
    }catch(bad_alloc){
        cerr << "Out of memory exception"  << nm << endl;
    }
}